package chances.epg.data.taglib;

import java.util.Date;
import java.util.List;

import javax.servlet.jsp.JspException;

import org.apache.commons.lang.StringUtils;

import chances.epg.data.PageBean;
import chances.epg.data.ScheduleVO;
import chances.epg.data.taglib.page.PageInfo;
import chances.epg.entity.content.EpgSchedule;

public class PlayPrevTag extends ScheduleBaseTag {

	private static final long serialVersionUID = 1L;
	private String var;
	private String mainFolder;
	private String tag;
	private String channelCode;
	private Date startTime;
	private int size = 10;//条目数
	
	@Override
	public int doStartTag() throws JspException {
		ScheduleVO scheduleVO = new ScheduleVO();
		scheduleVO.setChannelCode(this.channelCode);
		scheduleVO.setMainFolder(this.mainFolder);
		scheduleVO.setTag(this.tag);
		if(StringUtils.isNotBlank(this.getPageName())){
			this.queryScheduleByPage(scheduleVO);
		}else{
			this.queryScheduleBySize(scheduleVO);
		}
		return super.doStartTag();
	}
	
	public void queryScheduleBySize(ScheduleVO scheduleVO){
		List<EpgSchedule> result = null;
		result = this.getScheduleService().listPlayPrev(scheduleVO,this.start, this.size);
		setCollectionResult(result);
	}
	
	public void queryScheduleByPage(ScheduleVO scheduleVO){
		PageInfo pageInfo = this.createPageInfo(size);
		PageBean pageBean = pageInfo.getPageBean();
		pageBean.setSkip(this.start);
		List<EpgSchedule> result = null;
		result = this.getScheduleService().listPlayPrev(scheduleVO,this.startTime, pageBean);
		this.setPageInfo(pageInfo);
		setCollectionResult(result);
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}

	public String getMainFolder() {
		return mainFolder;
	}

	public void setMainFolder(String mainFolder) {
		this.mainFolder = mainFolder;
	}


	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	};
	
	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public String getChannelCode() {
		return channelCode;
	}

	public void setChannelCode(String channelCode) {
		this.channelCode = channelCode;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
}
